package com.shwread.android.qysw.adapter;

import android.content.Context;
import android.view.View;

import com.ciko.code.base.adapter.CommonAdapter;
import com.ciko.code.base.adapter.ViewHolder;
import com.ciko.code.bean.LeaderList;
import com.ciko.code.bean.MyBusinessTripBean;
import com.ciko.code.utils.DateUtil;

import java.util.List;

/**
 */
public class ApprovalProcessAdapter extends
        CommonAdapter<LeaderList>
{

    private  MyBusinessTripBean myBusinessTripBean;
    private List<LeaderList> mDatas;

    public ApprovalProcessAdapter(Context context, List<LeaderList> mDatas, int itemLayoutId, MyBusinessTripBean myBusinessTripBean) {
        super(context, mDatas, itemLayoutId);
        this.myBusinessTripBean = myBusinessTripBean;
        this.mDatas = mDatas;
    }

    @Override
    public void convert(ViewHolder helper, LeaderList item) {

        helper.setText(com.mywork.R.id.tvNum, helper.getPosition() + 1);
        if (helper.getPosition() == 0)
        {
            helper.getView(com.mywork.R.id.ll_ReciveTime).setVisibility(View.VISIBLE);
            helper.getView(com.mywork.R.id.ll_DealTime).setVisibility(View.GONE);
            helper.getView(com.mywork.R.id.ll_Advice).setVisibility(View.GONE);
            helper.setText(com.mywork.R.id.tvReciveTimeName, "申请时间：");
            helper.setText(com.mywork.R.id.tvReciveTime, DateUtil.longToDate(item.getCreateTime(), 4));
            helper.getView(com.mywork.R.id.iv_status).setVisibility(View.INVISIBLE);
            helper.getView(com.mywork.R.id.ll2).setVisibility(View.VISIBLE);
        }
        else
        {
            helper.getView(com.mywork.R.id.ll_ReciveTime).setVisibility(View.GONE);
            helper.getView(com.mywork.R.id.ll_DealTime).setVisibility(View.VISIBLE);
            helper.getView(com.mywork.R.id.ll_Advice).setVisibility(View.VISIBLE);
            helper.getView(com.mywork.R.id.ll2).setVisibility(View.GONE);
            helper.setText(com.mywork.R.id.tvDealTime, DateUtil.longToDate(item.getCreateTime(), 4));
            if (item.getDirection() == null)
            {
                helper.setText(com.mywork.R.id.tvAdvice, item.getFlowRecode());
            }
            else
            {
                helper.setText(com.mywork.R.id.tvAdvice, item.getDirection());
            }
            helper.getView(com.mywork.R.id.iv_status).setVisibility((item.getFlowRecode() == null || item.getFlowRecode().equals("")) ? View.INVISIBLE : View.VISIBLE);
//            helper.getView(com.mywork.R.id.iv_status).setBackgroundResource(item.getFlowRecode().equals("同意") ? com.mywork.R.drawable.res_agree_bg : com.mywork.R.drawable.res_refuse_bg);
            if ("同意".equals(item.getFlowRecode())){
                helper.getView(com.mywork.R.id.iv_status).setBackgroundResource(com.mywork.R.drawable.res_agree_bg);
            }else if ("否决".equals(item.getFlowRecode())){
                helper.getView(com.mywork.R.id.iv_status).setBackgroundResource(com.mywork.R.drawable.res_refuse_bg);

            }
            if (helper.getPosition() == mDatas.size()-1 )
            {
                if ("审批中".equals(item.getNextNodeName())){
                    helper.getView(com.mywork.R.id.iv_status).setBackgroundResource(com.mywork.R.drawable.res_agree_bg);

                }else if ("审批不通过".equals(item.getNextNodeName())){
                    helper.getView(com.mywork.R.id.iv_status).setBackgroundResource(com.mywork.R.drawable.res_refuse_bg);
                }
//                helper.getView(com.mywork.R.id.iv_status).setBackgroundResource(com.mywork.R.drawable.renshi_finish);
//                helper.getView(com.mywork.R.id.iv_status).setBackgroundResource(com.mywork.R.drawable.renshi_finish);
//                helper.getView(com.mywork.R.id.ll_Advice).setVisibility(View.GONE);
            }
        }
        if ("1".equals(item.getUserRole())){
            helper.setText(com.mywork.R.id.tvJob, "客服经理");
        }else if ("2".equals(item.getUserRole())){
            helper.setText(com.mywork.R.id.tvJob, "客户");
        }else if ("3".equals(item.getUserRole())){
            helper.setText(com.mywork.R.id.tvJob, "系统管理员");
        }/*else if ("4".equals(item.getUserRole())){
            helper.setText(com.mywork.R.id.tvJob, "未知");
        }*/else if ("5".equals(item.getUserRole())){
            helper.setText(com.mywork.R.id.tvJob, "总经理");
        }else if ("6".equals(item.getUserRole())){
            helper.setText(com.mywork.R.id.tvJob, "机构正职");
        }else if ("7".equals(item.getUserRole())){
            helper.setText(com.mywork.R.id.tvJob, "机构副职");
        }else if ("8".equals(item.getUserRole())){
            helper.setText(com.mywork.R.id.tvJob, "部门正职");
        }else if ("9".equals(item.getUserRole())){
            helper.setText(com.mywork.R.id.tvJob, "部门副职");
        }else if ("10".equals(item.getUserRole())){
            helper.setText(com.mywork.R.id.tvJob, "一般员工");
        }else if ("11".equals(item.getUserRole())){
            helper.setText(com.mywork.R.id.tvJob, "分公司中层干部、中心支公司及直属支公司班子成员");
        }else if ("12".equals(item.getUserRole())){
            helper.setText(com.mywork.R.id.tvJob, "人力资源部");
        }else if ("13".equals(item.getUserRole())){
            helper.setText(com.mywork.R.id.tvJob, "科长");
        }else if ("14".equals(item.getUserRole())){
            helper.setText(com.mywork.R.id.tvJob, "分管总");
        }
//        helper.setText(com.mywork.R.id.tvJob, item.getUserRole());
        helper.setText(com.mywork.R.id.tvName, item.getPerUserName());
        helper.setRoundImageUrl(com.mywork.R.id.ivHanderIcon, mDatas.get(helper.getPosition()).getUserHead(), com.mywork.R.drawable.test_header);
    }



}
